//
//  WYROneViewController.m
//  10-21-快速搭建框架
//
//  Created by lkx0 on 16/10/21.
//  Copyright © 2016年 lkx0. All rights reserved.
//

#import "WYROneViewController.h"
#import "WYRTwoViewController.h"
#import "WYRTabBarViewController.h"
#import "WYRFiveViewController.h"

@interface WYROneViewController ()

//设置两个全局变量
@property (nonatomic, strong) UITextField * countField;
@property (nonatomic, strong) UITextField * passWordField;


@end

@implementation WYROneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
        //手动添加登录界面的所有控件
    [self setAllControllers];

     //隐藏工具栏
      // self.tabBarController.tabBar.hidden=YES;
    
    // Do any additional setup after loading the view.
}
#pragma mark -控件实现方法

-(void)setAllControllers{
    //1.风云登录界面  UILable
    [self setLoginLable];
    //2.账号: UILable
    [self setCountLable];
    //3. 账号输入框: UITextField
    [self setCountField];
    //4.密码: UILable
    [self setPassWordLable];
    //5.密码输入框: UITextField
    [self setPassWordField];
    //6.登录界面: UIButton
    [self setLoginButton];
    //7.注册按钮: UIButton
    [self setRegistButton];
   

}


-(void)setLoginLable{
    //1.风云登录界面  UILable
    UILabel * loginLable=[[UILabel alloc]initWithFrame:CGRectMake(50, 100, 220, 60)];
    //设置标签的背景色
    loginLable.backgroundColor=[UIColor yellowColor];
    //设置标签的文字
    loginLable.text=@"风云登录界面";
    //设置标签文字的对齐方式（居中）
    loginLable.textAlignment=NSTextAlignmentCenter;
    //设置标签文字的大小
    loginLable.font=[UIFont systemFontOfSize:30];
    [self.view addSubview:loginLable];
}


-(void)setCountLable{
    UILabel * countLable=[[UILabel alloc]initWithFrame:CGRectMake(10, 190, 90, 45)];
 //   countLable.backgroundColor=[UIColor blueColor];
        countLable.text=@"账号";
    countLable.textAlignment=NSTextAlignmentCenter;
    countLable.font=[UIFont systemFontOfSize:25];
    [self.view addSubview:countLable];

}


-(void)setCountField{
    _countField=[[UITextField alloc]initWithFrame:CGRectMake(100, 190, 200, 45)];
    _countField.borderStyle=UITextBorderStyleLine;
     _countField.layer.borderWidth=2.0f;
    _countField.placeholder=@"请输入账号";
    _countField.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:_countField];
}

-(void)setPassWordLable{
    UILabel * passWordLable=[[UILabel alloc]initWithFrame:CGRectMake(10, 265, 90, 45)];
    //   countLable.backgroundColor=[UIColor blueColor];
    passWordLable.text=@"密码";
    passWordLable.textAlignment=NSTextAlignmentCenter;
    passWordLable.font=[UIFont systemFontOfSize:25];
    [self.view addSubview:passWordLable];
}

-(void)setPassWordField{
    _passWordField=[[UITextField alloc]initWithFrame:CGRectMake(100, 265, 200, 45)];
    _passWordField.borderStyle=UITextBorderStyleLine;
    _passWordField.placeholder=@"请输入密码";
    _passWordField.textAlignment=NSTextAlignmentCenter;
    
    _passWordField.secureTextEntry=YES;
    [self.view addSubview:_passWordField];
}

-(void)setLoginButton{
    UIButton * loginButton=[[UIButton alloc]initWithFrame:CGRectMake(60, 350, 100, 45)];
    loginButton.backgroundColor=[UIColor grayColor];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    //点击事件
    [loginButton addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:loginButton];
   }

-(void)setRegistButton{
    UIButton * registButton=[[UIButton alloc]initWithFrame:CGRectMake(170, 350, 100, 45)];
    registButton.backgroundColor=[UIColor grayColor];
    [registButton setTitle:@"注册" forState:UIControlStateNormal];
    [registButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
  //添加注册事件
    [registButton addTarget:self action:@selector(registClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:registButton];
}

-(void)loginClick{
    //定义自己的账号和密码
    NSString * strCount = self.countField.text;
    NSString * strPassWord =self.passWordField.text;
    //判断文本框输入的账号和密码是否与自己原有的相同
    if([strCount isEqualToString:@""] && [strPassWord isEqualToString:@""]){
        //实现跳转,跳转到下一个界面
        WYRTabBarViewController * tabBar = [[WYRTabBarViewController alloc]init];
        [self.navigationController pushViewController:tabBar animated:YES];
    }else{
        UIAlertView * alert=[[UIAlertView alloc]initWithTitle:@"notice" message:@"账号密码错误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"正确", nil];
        [alert show];
    }
    
}
//-(void)viewWillAppear:(BOOL)animated{
//    self.hidesBottomBarWhenPushed = NO;
//}

//实现注册按钮的点击方法  registClick
-(void)registClick{
    WYRFiveViewController * fiveView =[[WYRFiveViewController alloc]init];
    [self.navigationController pushViewController:fiveView animated:YES];
        
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
